package ${package.Controller};

<#--import com.digital.smartgrow.dto.${entity}PageDTO;-->
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@Api(tags = "${table.comment!}")
@RestController
<#else>
@Controller
</#if>
@RequestMapping("${r"${context.prefix}"}/syc<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${table.entityPath}Service;

    @ApiOperation(value = "${table.comment!}-分页查询")
    @PostMapping("/list")
    public Object getListByPage(@RequestBody ${entity}PageDTO ${table.entityPath}PageDTO){
        return ${table.entityPath}Service.getListByPage(${table.entityPath}PageDTO);
    }

    @ApiOperation(value = "${table.comment!}-详情")
    @GetMapping("/{id}")
    public Object getInfo(@PathVariable Integer id){
        if (id == null) return Result.fail("id不能为空");
        return ${table.entityPath}Service.getInfo(id);
    }

    @ApiOperation(value = "${table.comment!}-删除")
    @DeleteMapping("/{id}")
    public Object removeById(@PathVariable Integer id){
      if (id == null) return Result.fail("id不能为空");
      return ${table.entityPath}Service.removeById(id);
    }
    @ApiOperation(value = "${table.comment!}-新增")
    @PostMapping()
    public Object add( @RequestBody  ${entity} ${table.entityPath}){
       return ${table.entityPath}Service.save(${table.entityPath});
    }

    @ApiOperation(value = "${table.comment!}-编辑")
    @PutMapping()
    public Object edit(@RequestBody ${entity} ${table.entityPath}){
    if (${table.entityPath}==null||${table.entityPath}.getId() == null)
       return Result.fail("id不能为空");
       return ${table.entityPath}Service.updateById(${table.entityPath});
    }
}
</#if>
